import { getUserGetRepos } from '@/services/codeTrail/yonghu';
import { GithubOutlined, PlusOutlined } from '@ant-design/icons';
import { PageContainer, ProCard } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { theme } from 'antd';
import React, { useEffect, useState } from 'react';
import RepositoryBox from '../components/RepositoryBox';
import styles from './index.module.less';
import AddForm from '../components/AddForm';

const RepositoryList: React.FC = () => {
  const { token } = theme.useToken();
  const { initialState } = useModel('@@initialState');
  const [repos, setRepos] = useState<API.repoData[] | null>([]);
  useEffect(() => {
    const fetchRepos = async () => {
      try {
        const response = await getUserGetRepos();
        if (response.code === 200 && Array.isArray(response.data)) {
          setRepos(response.data);
        } else {
          console.error('Error fetching repos:', response);
        }
      } catch (error) {
        console.error('Error fetching repos:', error);
      }
    };

    fetchRepos();
  }, []);
  return (
    <PageContainer>
      <ProCard className={styles.container}>
        <ProCard
          title="仓库管理"
          extra={
            <AddForm/>
          }
          bordered
          headerBordered
        >
          <ProCard colSpan="100%">
            <div className={styles.giteeBox}>
              <div className={styles.title}>
                <GithubOutlined style={{ fontSize: '32px' }} className={styles.icon} />
                <div>gitee仓库</div>
              </div>
              <div className={styles.boxs}>
                {repos?.map((repo, index) =>
                  repo ? (
                    <div className={styles.box}>
                      <RepositoryBox key={index} data={repo} />
                    </div>
                  ) : null,
                )}
              </div>
            </div>
          </ProCard>
        </ProCard>
      </ProCard>
    </PageContainer>
  );
};

export default RepositoryList;
